package com.googlecode.afdbaccess.web.portal.webcontent.edit_row.edit_row_form_data;

import javax.annotation.security.RolesAllowed;
import javax.inject.Inject;
import javax.servlet.http.HttpServletRequest;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Context;

import org.jboss.resteasy.annotations.Form;

import com.googlecode.afdbaccess.cache.preparedstatement.PreparedStatementArgumentsSetterHelper;
import com.googlecode.afdbaccess.config.injectconfig.ManagedRequestTransaction;
import com.googlecode.afdbaccess.web.common.interceptors.DatabaseAccessing;
import com.googlecode.afdbaccess.web.common.interceptors.RequestLogged;
import com.googlecode.afdbaccess.web.common.json.ExtJsJsonResponse;

@RolesAllowed("theRole")
@RequestLogged
@DatabaseAccessing
@Path("edit-row/edit-row-form-data")
public class EditRowPostRest {
    @Inject
    private ManagedRequestTransaction t;

    @POST
    @Produces("application/json")
    public ExtJsJsonResponse create(@SuppressWarnings("unused") @Context HttpServletRequest request, @Form FormValues formValues) throws Exception {
        formValues.checkParams();

        String sql =
            "INSERT INTO webTable(stringAttribute)\n" +
            "VALUES(?)\n";

        PreparedStatementArgumentsSetterHelper setter = new PreparedStatementArgumentsSetterHelper();
        setter.addArgument(formValues.stringAttribute);

        t.executeInsert(sql, setter);
        
        return new ExtJsJsonResponse();
    }
}
